<?php

// use Illuminate\Support\Facades\Schema;
use Jialeo\LaravelSchemaExtend\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class InitActivityUser extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 参与记录
        Schema::create('activity_records', function (Blueprint $table) {
            $table->comment = '活动参与记录表';
            
            $table->increments('id');
            $table->uuid('uuid')->index() ;

            $table->integer('user_id')->index()->comment('用户id'); // 用户id
            $table->integer('activity_id')->index()->comment('用户id'); // 用户id
            $table->integer('order_id')->index()->nullable()->comment('订单id'); // 订单id
            $table->string('join_code', 30)->nullable()->comment('参与码'); // 参与码

            // $table->integer('power')->default(10)->index()->comment('能量值 (决定中奖概率)'); // 能量值 (决定中奖概率)

            $table->boolean('is_lucky_user')->default(0)->index()->comment('是否中奖'); // 是否中奖

            $table->tinyInteger('status')->index()->default(0)->nullable()->comment('0正常'); // 0正常

            $table->softDeletes();
            $table->timestamps();
        });

        // 助力记录
        Schema::create('activity_invite_records', function (Blueprint $table) {
            $table->comment = '活动助力记录表';
            
            $table->increments('id');
            $table->uuid('uuid')->index() ;

            $table->integer('user_id')->index()->comment('用户id'); // 用户id
            $table->integer('activity_id')->index()->comment('用户id'); // 用户id
            $table->integer('activity_record_id')->nullable()->index()->comment('用户参与记录id'); // 用户id

            $table->integer('order_id')->index()->nullable()->comment('订单id'); // 订单id

            $table->integer('invitee_id')->index()->comment('受邀者id'); // 用户id
            $table->boolean('is_new_user')->index()->default(0)->comment('邀请的是否是新注册用户'); // 用户id

            $table->integer('reward_money')->nullable()->comment('砍价金额'); // 用户id
            $table->integer('reward_score')->nullable()->comment('砍价金额'); // 用户id
            $table->integer('reward_total')->nullable()->comment('数量: 如抽奖增加签号'); // 用户id

            $table->json('options')->nullable()->comment('options信息'); // 用户id

            $table->tinyInteger('status')->index()->default(0)->nullable()->comment('0正常'); // 0正常

            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::disableForeignKeyConstraints();
        Schema::dropIfExists('activity_records');
        Schema::dropIfExists('activity_invite_records');
    }
}
